fix: std.parseYaml YAML 1.2 octal (0o777) and document marker handling#968
Draft
He-Pin wants to merge 3 commits into
Draft
fix: std.parseYaml YAML 1.2 octal (0o777) and document marker handling#968He-Pin wants to merge 3 commits into
He-Pin wants to merge 3 commits into
Conversation
3d07aba to
58d6d9c
Compare
This was referenced Jun 18, 2026
58d6d9c to
2240e17
Compare
Motivation:
Two issues in std.parseYaml diverging from go-jsonnet:
1. SnakeYAML's SafeConstructor uses YAML 1.1 type resolution which does
not recognize the 0o prefix for octal integers (YAML 1.2), causing
unquoted 0o777 to be parsed as string "0o777" instead of 511.
2. Explicit document start markers (---) caused single-doc YAML to be
returned directly instead of wrapped in an array as go-jsonnet does.
Modification:
Replaced SafeConstructor-based parsing with composeAll() + custom
yamlNodeToJson() that handles YAML 1.2 octal (0o prefix) for plain
scalars while preserving quoted values as strings. Added
YamlDocStartPattern regex to detect explicit --- and wrap single-doc
results in an array.
Result:
std.parseYaml now matches go-jsonnet for both YAML 1.2 octal syntax
and document start marker handling.
| YAML input | go-jsonnet v0.22.0 | jrsonnet 0.5.0-pre99 | sjsonnet (before) | sjsonnet (after) |
|-----------|-------------------|---------------------|-------------------|-----------------|
| 0o777 | 511 | 511 | "0o777" (bug) | 511 |
| -0o777 | -511 | -511 | "-0o777" (bug) | -511 |
| "0o777" | "0o777" | "0o777" | "0o777" | "0o777" |
| "---" | [null] | null | null (bug) | [null] |
| "---\na:1"| [{a:1}] | {a:1} | {a:1} (bug) | [{a:1}] |
| "a: 1" | {a:1} | {a:1} | {a:1} | {a:1} |
Note: jrsonnet does NOT wrap --- in array; sjsonnet aligns with go-jsonnet.
2240e17 to
cfb4b5b
Compare
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Two issues in
std.parseYamldiverging from go-jsonnet:SafeConstructoruses YAML 1.1 type resolution which does not recognize the0oprefix for octal integers (YAML 1.2), causing unquoted0o777to be parsed as string"0o777"instead of 511.---) caused single-doc YAML to be returned directly instead of wrapped in an array as go-jsonnet does.Modification
src-jvm/Platform.scala): ReplacedSafeConstructor-based parsing withcomposeAll()+ customyamlNodeToJson()that handles YAML 1.2 octal (0oprefix), hex (0x), binary (0b), sexagesimal, and special float values for plain scalars while preserving quoted values as strings. AddedYamlDocStartPatternregex to detect explicit---and wrap single-doc results in an array.src-js/Platform.scala): AddedYaml12OctalPatternmatching andisQuotedScalarposition check to detect YAML 1.2 octal in the scala-yamlNoderepresentation. Added same document marker detection.Result
std.parseYamlnow matches go-jsonnet for both YAML 1.2 octal syntax and document start marker handling.YAML 1.2 Octal
a: 0777511511511b: 0o777511"0o777"(bug)511d: 0o108"0o10"(bug)8e: -0o777-511"-0o777"(bug)-511f: "0o777""0o777""0o777""0o777"Document Markers
"---"[null]null(bug)[null]"---\na: 1"[{a:1}]{a:1}(bug)[{a:1}]"a: 1"{a:1}{a:1}{a:1}Test plan
parseyaml_yaml12_octal.jsonnetandparseyaml_doc_marker.jsonnet)